package com.baidu.bulls.stock.admin.user.config;

import com.baidu.bulls.stock.entity.user.AuthorityMenu;
import com.baidu.bulls.stock.entity.vo.ParentAuthorityMenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
import org.springframework.data.rest.core.config.MetadataConfiguration;
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;

import javax.persistence.EntityManager;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * 实体类返回id配置
 */
@Configuration
public class RestEntityIdConfiguration extends RepositoryRestConfigurerAdapter {

    @Autowired
    private EntityManager entityManager;

    @Override
    public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
        /**
         *  第一行代码是配置所有实体类返回id
         *  第二行是配置指定实体类返回id
         */
       config.exposeIdsFor(entityManager.getMetamodel().getEntities().stream().map(e -> e.getJavaType()).collect(Collectors.toList()).toArray(new Class[0]));
//        config.exposeIdsFor(AuthorityMenu.class, ParentAuthorityMenuVo.class);
    }
}
